import {
  Controller,
  Get,
  Post,
  Body,
  Patch,
  Param,
  Delete,
  ParseIntPipe,
  Query,
} from '@nestjs/common';
import { ClassificationService } from './classification.service';
import { CreateClassificationDto } from './dto/create-classification.dto';
import { UpdateClassificationDto } from './dto/update-classification.dto';
import { ApiOperation, ApiQuery, ApiTags } from '@nestjs/swagger';

@ApiTags('分类管理')
@Controller('classification')
export class ClassificationController {
  constructor(private readonly classificationService: ClassificationService) {}

  @ApiOperation({ summary: '新增分类' })
  @Post()
  create(@Body() createClassificationDto: CreateClassificationDto) {
    return this.classificationService.create(createClassificationDto);
  }

  @ApiOperation({ summary: '分页查询分类列表' })
  @ApiQuery({
    name: 'page',
    type: Number,
    description: '当前页码',
    required: true,
    example: 1,
  })
  @ApiQuery({
    name: 'pageSize',
    type: Number,
    description: '分页大小',
    required: true,
    example: 10,
  })
  @ApiQuery({
    name: 'name',
    type: String,
    description: '分类名称',
    required: false,
    example: '',
  })
  @ApiQuery({
    name: 'keywords',
    type: String,
    description: '关键词',
    required: false,
    example: '',
  })
  @ApiQuery({
    name: 'sortFeild',
    type: String,
    description: '排序字段',
    required: false,
    example: '',
  })
  @ApiQuery({
    name: 'sort',
    type: String,
    description: '排序方式[DESC:升序]、[ASC降序]',
    required: false,
    example: '',
  })
  @Get()
  findAll(
    @Query('page', new ParseIntPipe()) page = 1,
    @Query('pageSize', new ParseIntPipe()) pageSize = 10,
    @Query('name') name?: string,
    @Query('keywords') keywords?: string,
    @Query('sortFeild') sortFeild?: string,
    @Query('sort') sort?: string,
  ) {
    return this.classificationService.findAll({
      page,
      pageSize,
      name,
      keywords,
      sortFeild,
      sort,
    });
  }

  @ApiOperation({ summary: '查询所有分类列表' })
  @Get('list')
  findList() {
    return this.classificationService.findAllList();
  }

  @ApiOperation({ summary: '查询分类详情' })
  @Get(':id')
  findOne(@Param('id') id: string) {
    return this.classificationService.findOne(id);
  }

  @ApiOperation({ summary: '更新分类数据' })
  @Patch(':id')
  update(
    @Param('id') id: string,
    @Body() updateClassificationDto: UpdateClassificationDto,
  ) {
    return this.classificationService.update(id, updateClassificationDto);
  }

  @ApiOperation({ summary: '删除分类' })
  @Delete(':id')
  remove(@Param('id') id: string) {
    return this.classificationService.remove(id);
  }
}
